/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


Ext.onReady(function(){
    var relate_demension_grid;
    var xg = Ext.grid;  
    var psize = 15;
    var store;
    var openUrl;
   // repid=218

   var jReader1 = new Ext.data.JsonReader( {
        root : 'data',
        totalProperty : 'totalCount',
        fields : [{
            name : 'repid'
        }, {
            name : 'repcode'
        }, {
            name : 'repname'
        }, {
            name : 'cataname'
        }]
    });
    
    openUrl=basePath + 'JarpListener?className=cn.com.jsepc.rep.report.GetRepPara';
    openUrl += '&methodName=get_rep_para&paramCount=3';
	
  store = new Ext.data.Store( {
        //storeId : 'store1',
        proxy : new Ext.data.HttpProxy( {
            url : openUrl
        }),
        reader : jReader1,
        baseParams : {
            param_0 : 0,
            param_1 : psize,
            param_2:repid
        }
    });
    

    var sm = new xg.CheckboxSelectionModel({
        });
	
    var cm = new xg.ColumnModel( [
        sm,							
        {
            hidden:true,
            header : '指标编号',
            sortable : true,
            // hidden : true,
            dataIndex : 'repid'
        },{
            header : '指标编码',
            sortable : true,
            dataIndex : 'repcode'
        },{
            header : '指标名称',
            sortable : true,
            dataIndex : 'repname'
        }, {
            header : '所属分类',
            sortable : true,
            //  hidden : true,
            dataIndex : 'cataname'
        }
        ]);
	     
    cm.defaultSortable = true;
    relate_demension_grid = new Ext.grid.GridPanel({
        region : 'center',
        store : store,
        id:'relate_demension_grid',
        viewConfig : {
            forceFit : true
        },
        sm : sm,
        cm : cm,
        frame : true,
        columnLines : true,
        loadMask:true,
        region:"center",
        height:500,
        stateful : true,
        stateId : 'relate_demension_grid',
        bbar : new Ext.PagingToolbar( {
            store : store,
            paramNames : {
                start : 'param_0',
                limit : 'param_1'
            },
            emptyMsg : '没有数据需要显示',
            displayInfo : true,
            pageSize : 15
            
        })
    }); 
    store.load();
    
    
    var viewport = new Ext.Viewport({
        layout : 'border',
        items:[{
            tbar : [{
                text : '新增',
                handler : function() {
                	
                    window.showModalDialog("subject_report.jsp?id="+repid, '','dialogWidth=900px;dialogHeight=600px;status:no;resizable:yes;');
                    Ext.getCmp("relate_demension_grid").store.reload();
                }
            }, '-', {
                xtype:'button',
                text : '删除',
                id:'delete_catalog_button',
                handler : function() {
                var row = relate_demension_grid.getSelectionModel().getSelections(); 

        if(row.length==0){
            Ext.MessageBox.alert("提示","请勾选需要删除的指标！")
            return ;
        }
                    Ext.MessageBox.show({
                    title:'提示',
                    msg: '是否确定删除？',
                    buttons:{
                        'yes':'删除',
                        'no':'取消'
                    },
                    fn: save_or_no,
                    animEl: 'delete_process_button',
                    icon: Ext.MessageBox.QUESTION
                });
                function save_or_no(btn){
                    if(btn=='yes'){
                       delete_rep_para();
                    }
                    else if(btn=='no'){
                         return ;
                    }
                };
                    
                }
            },'-',{
            text:'关闭',
             handler : function() {
                 window.close();
            }      
          }
            ],
            region : 'center',
            deferredRender : false,
            activeTab : 0,
            layout : 'border',
            items:[relate_demension_grid]
        }]

    })

function delete_rep_para(){
var row = relate_demension_grid.getSelectionModel().getSelections(); 

        var array=new Array(row.length);
        for(var i=0;i<row.length;i++){
            array[i]=row[i].get('repid');    
        }
        var saveItemInfoUrl = "";
        saveItemInfoUrl = '?className=cn.com.jsepc.rep.report.GetRepPara';
        saveItemInfoUrl += '&methodName=delete_rep_para';
        saveItemInfoUrl += '&paramCount=2'+'&param_0='+ repid+"&param_1="+array;

        saveItemInfoUrl = basePath + 'JarpListener' + saveItemInfoUrl;
        httpR_itemInfo = getXMLHttpRequest();
        httpR_itemInfo.onreadystatechange = returnItemUpdate;
        httpR_itemInfo.open("POST", saveItemInfoUrl, true);
        httpR_itemInfo.send();
        function returnItemUpdate() {
            if (httpR_itemInfo.readyState == 4) {
                if (httpR_itemInfo.status == 200) { 
                    ret = httpR_itemInfo.responseText;
                    if (ret=='ok'){
                        Ext.Msg.alert('提示','删除成功！');
                        var grid = Ext.ComponentMgr.get("relate_demension_grid");
                        grid.store.reload();
                    }else{
                        Ext.Msg.alert('提示','删除失败！');
                    }
                }
            }
        }
}

})